#!/bin/sh
case $1 in
    namesrv)

    nohup sh rocketmq/bin/mqnamesrv $@ &> /home/logs/mqnamesrv.log &
    echo "mqnamesrv start success"
    ;;

    broker)

    echo "broker starting"

    nohup sh rocketmq/bin/mqbroker -n $2 -c rocketmq/conf/broker.conf autoCreateTopicEnable=true autoCreateSubscriptionGroup=true &> /home/logs/mqbroker.log &
    echo "broker start success"
    ;;

    brokers)

    echo "broker-$2 starting"

    nohup sh rocketmq/bin/mqbroker -n $3 -c rocketmq/conf/2m-2s-async/broker-$2.properties autoCreateTopicEnable=true autoCreateSubscriptionGroup=true &> /home/logs/mqbroker-$2.log &
    echo "broker-$2 start success"
    ;;

    single)

    echo "will be start single mq"
    sh mq-linux namesrv -n eplus-mq:9876
    sleep 2
    sh mq-linux broker eplus-mq:9876

    ;;

    console)

    nohup java -Xms100m -Xmx2048m -jar rocketmq/console/rocketmq-console.jar --server.port=8765 &> /home/logs/mqconsole.log &
    echo "console start success"

    ;;

    stop)

    sh rocketmq/bin/mqshutdown broker
    sh rocketmq/bin/mqshutdown namesrv

    ;;
    restart)

    sh mq-linux stop
    sleep 2
    sh mq-linux single

    ;;
    *)
    echo "sh mq-linux stop"
    echo "sh mq-linux single"
    echo "sh mq-linux console"
    echo "sh mq-linux namesrv || sh mq-linux namesrv -n localhost:9876"
    echo "sh mq-linux broker localhost:9876"
    echo "sh mq-linux brokers a || a-s localhost:9876;other-localhost:9876"
esac
